import React, { useState } from 'react'

export default function index() {
  const [state, setState] = useState(0)
  // or
  // const [state, setState] = useState(() => 0)
  const add = () => {
    // setState(state+1)
    // setState(state+1)
    // setState(state+1)
    // 这种不对  此时这里state的值不是最新的且是相同的与页面上的值对不上  
    console.log(state)
    // 正确
    setState((pre) => pre+1)
     setState((pre) => pre+1)
     setState((pre) => pre+1)
     console.log(state)
  }
  return (
    <>
      <div>{ state }</div>
      <button onClick={add}>加一</button>
    </>
  )
}
